home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 April: Mac OS SDK / Dev.CD Apr 97 SDK1.toast / Development Kits (Disc 1) / Communications Toolbox / CTB Sample Code 1.0b16 / CTB Sources / Sources 2 / File Transfer Tool for CTB / fdef.c next >
Encoding:
C/C++ Source or Header  |  1989-10-06  |  5.4 KB  |  237 lines  |  [TEXT/MPS ]

  1. /************************************************************************************
  2. *
  3. *  Project Name:    FTTools
  4. *     File Name:    fdef.c
  5. *        Author:    Rob Neville (IIx)
  6. *          Date:    May 17, 1989
  7. *
  8. *   Description:    Template fdef function. 
  9. *
  10. *************************************************************************************
  11. *
  12. *    Revision History:
  13. *        5/17/89 - Original version by Rob Neville (IIx)
  14. *
  15. ************************************************************************************/
  16.  
  17. #include "FTTool.h"
  18.  
  19. pascal long FDEF(hTH,msg,p1,p2,p3)
  20. ToolHandle    hTH;
  21. short        msg;
  22. long        p1,p2,p3;
  23. {
  24.     long    theErr;
  25.     long     ToolInit(ToolHandle);
  26.     long    ToolDispose(ToolHandle);
  27.     long    ToolSuspend(ToolHandle);
  28.     long     ToolResume(ToolHandle);
  29.     long    ToolMenu(ToolHandle,short,short);
  30.     long    ToolEvent(ToolHandle,EventRecord *);
  31.     long     ToolActivate(ToolHandle);
  32.     long    ToolDeactivate(ToolHandle);
  33.     long    ToolAbort(ToolHandle);
  34.     long     ToolStart(ToolHandle,short,SFReply *);
  35.     long    ToolExec(ToolHandle);
  36.     
  37.     switch (msg)
  38.     {
  39.         case InitMsg:
  40.             theErr = ToolInit(hTH);                        /* below */
  41.             break;
  42.         case DisposeMsg:
  43.             theErr = ToolDispose(hTH);                    /* below */
  44.             break;
  45.         case SuspendMsg:
  46.             theErr = ToolSuspend(hTH);                    /* below */
  47.             break;
  48.         case ResumeMsg:
  49.             theErr = ToolResume(hTH);                        /* below */        
  50.             break;
  51.         case MenuMsg:
  52.             theErr = ToolMenu(hTH,(short)p1,(short)p2);    /* below */
  53.             break;
  54.         case EventMsg:
  55.             theErr = ToolEvent(hTH,(EventRecord *)p1);    /* below */
  56.             break;
  57.         case ActivateMsg:
  58.             theErr = ToolActivate(hTH);                    /* below */
  59.             break;
  60.         case DeactivateMsg:
  61.             theErr = ToolDeactivate(hTH);                    /* below */
  62.             break;
  63.         case AbortMsg:
  64.             theErr = ToolAbort(hTH);                        /* below */
  65.             break;
  66.         case StartMsg:
  67.             theErr = ToolStart(hTH,(short)p1,(SFReply *)p2); /* below */
  68.             break;
  69.         case ExecMsg:
  70.             theErr = ToolExec(hTH);                        /* below */
  71.             break;
  72.         default:                        /* we should never get this */
  73.             theErr = NotSupported;    /* I don't support unsupported messages */
  74.             break;
  75.     }
  76.     return (theErr);
  77.     #pragma unused (p3)
  78. }
  79.  
  80. long ToolInit(ToolHandle hTH)
  81. {
  82.     PrivatePtr    private;
  83.     Str255        autoName = "tallyho";
  84.     
  85.     if ((**hTH).procID < 3)
  86.     {
  87.         DebugStr("\pPipe is blocked!!! Call New!!;hc;g");
  88.         (**hTH).errCode = Failed;
  89.         return (Failed);
  90.     }
  91.     private = (PrivatePtr)NewPtrClear(sizeof(Private));
  92.     if (private == nil)
  93.     {
  94.         (**hTH).errCode = OutOfMemory;
  95.         return (OutOfMemory);
  96.     }
  97.     else
  98.         (**hTH).ftPrivate = (Ptr)private;
  99.     (**hTH).autoRec[0] = strlen(autoName);
  100.     strcpy(&(**hTH).autoRec[1],autoName);
  101.     return (NoErr);
  102. }
  103.  
  104. long ToolDispose(ToolHandle hTH)
  105. {
  106.     if ((**hTH).procID < 3)
  107.     {
  108.         DebugStr("\pPipe is blocked!!! Call Dispose!!;hc;g");
  109.         (**hTH).errCode = Failed;
  110.         return (Failed);
  111.     }
  112.     DisposPtr((**hTH).ftPrivate);            /* dispose my only data structure */
  113.     return (NoErr);
  114. }
  115.  
  116. long ToolSuspend(ToolHandle hTH)
  117. {
  118.     if ( ( (**hTH).procID < 3) || ( (**hTH).ftPrivate == nil ) ) /* not a valid hTH */
  119.     {
  120.         DebugStr("\pPipe is blocked!!! Call Suspend!!;hc;g");
  121.         return (Failed);
  122.     }
  123.     return (NoErr);
  124. }
  125.  
  126. long ToolResume(ToolHandle hTH)
  127. {
  128.     if ( ( (**hTH).procID < 3) || ( (**hTH).ftPrivate == nil ) ) /* not a valid hTH */
  129.     {
  130.         DebugStr("\pPipe is blocked!!! Call Resume!!;hc;g");
  131.         return (Failed);
  132.     }
  133.     return (NoErr);
  134. }
  135.  
  136. long ToolMenu(ToolHandle hTH,short p1,short p2)
  137. {
  138.     if ( ( (**hTH).procID < 3 ) || ( (**hTH).ftPrivate == nil ) ) /* not a valid hTH */
  139.     {
  140.         DebugStr("\pPipe is blocked!!! Call Menu!! In Handle;hc;g");
  141.         (**hTH).errCode = Failed;
  142.         return (Failed);
  143.     }
  144.     if (p1 >= 32767 || p1 <= -32768)
  145.     {
  146.         DebugStr("\pPipe is blocked!!! Call Menu!! Invalid p1;hc;g");
  147.         (**hTH).errCode = Failed;
  148.         return (Failed);
  149.     }
  150.     if (p2 >= 32767 || p2 <= -32768)
  151.     {
  152.         DebugStr("\pPipe is blocked!!! Call Menu!! Invalid p2;hc;g");
  153.         (**hTH).errCode = Failed;
  154.         return (Failed);
  155.     }
  156.     return (NoErr);
  157. }
  158.  
  159. long ToolEvent(ToolHandle hTH,EventRecord *theEvent) /* Don't pass this a NullEvent PLEASE */
  160. ToolHandle     hTH;
  161. {
  162.     if ( ((**hTH).procID < 3) || ((**hTH).ftPrivate == nil) ) /* not a valid hTH and what is empty */
  163.     {
  164.         DebugStr("\pPipe is blocked!!! Call Event!! In Handle;hc;g");
  165.         return (Failed);
  166.     }
  167.     if (theEvent->what == 0 )
  168.     {
  169.         DebugStr("\pPipe is blocked!!! Call Event!! p1;hc;g");
  170.         return (Failed);
  171.     }
  172.     return (NoErr);
  173. }
  174.  
  175. long ToolActivate(ToolHandle hTH)
  176. {
  177.     if ( ( (**hTH).procID < 3 ) || ( (**hTH).ftPrivate == nil ) ) /* not a valid hTH */
  178.     {
  179.         DebugStr("\pPipe is blocked!!! Call Activate!!;hc;g");
  180.         return (Failed);
  181.     }
  182.     return (NoErr);
  183. }
  184.  
  185. long ToolDeactivate(ToolHandle hTH)
  186. {
  187.     if ( ( (**hTH).procID < 3 ) || ( (**hTH).ftPrivate == nil ) ) /* not a valid hTH */
  188.     {
  189.         DebugStr("\pPipe is blocked!!! Call Deactivate!!;hc;g");
  190.         return (Failed);
  191.     }
  192.     return (NoErr);
  193. }
  194.  
  195. long ToolAbort(ToolHandle hTH)
  196. {
  197.     if ( ( (**hTH).procID < 3 ) || ( (**hTH).ftPrivate == nil ) ) /* not a valid hTH */
  198.     {
  199.         DebugStr("\pPipe is blocked!!! Call Abort!!;hc;g");
  200.         return (Failed);
  201.     }
  202.     return (NoErr);
  203. }
  204.  
  205. long ToolStart(ToolHandle hTH,short p1,SFReply *p2)
  206. {
  207.     if ( ( (**hTH).procID < 3 ) || ( (**hTH).ftPrivate == nil ) ) /* not a valid hTH */
  208.     {
  209.         DebugStr("\pPipe is blocked!!! Call Start!! In Handle;hc;g");
  210.         return (Failed);
  211.     }
  212.     if (p1 < 0)
  213.     {
  214.         DebugStr("\pPipe is blocked!!! Call Start!! In p1;hc;g");
  215.         return (Failed);
  216.     }
  217.     if (p2 < 0)
  218.     {
  219.         DebugStr("\pPipe is blocked!!! Call Start!! In p2;hc;g");
  220.         return (Failed);
  221.     }
  222.     return (NoErr);
  223. }
  224.  
  225. long ToolExec(ToolHandle hTH)
  226. {
  227.     long     result = NoErr;
  228.     
  229.     if ( ( (**hTH).procID < 3 ) || ( (**hTH).config == nil ) ) /* not a valid hTH */
  230.     {
  231.         DebugStr("\pPipe is blocked!!! Call Exec!!;hc;g");
  232.         return (Failed);
  233.     }
  234.     return (NoErr);
  235. }
  236.  
  237.